/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.yuhanginfo.modules.sys.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yuhanginfo.common.persistence.Page;
import com.yuhanginfo.common.web.BaseController;
import com.yuhanginfo.modules.sys.entity.ReturnsGoods;
import com.yuhanginfo.modules.sys.entity.Store;
import com.yuhanginfo.modules.sys.entity.User;
import com.yuhanginfo.modules.sys.service.OrdersExchangeHistoryService;
import com.yuhanginfo.modules.sys.service.StoreService;
import com.yuhanginfo.modules.sys.utils.UserUtils;

/**
 * 退换货记录Controller
 * @author yinhao
 * @version 2017-11-21
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/ordersexchangehistory")
public class OrdersExchangeHistoryController extends BaseController {
	
	private static final  Logger logger = LoggerFactory.getLogger(OrdersExchangeHistoryController.class);
	
	@Autowired
	private OrdersExchangeHistoryService ordersExchangeHistoryService;
	
	@Autowired
	private StoreService storeService;

	@RequiresPermissions("sys:ordersexchangehistory:view")
	@RequestMapping(value = {"list", ""})
	public String list(ReturnsGoods returnsGoods, HttpServletRequest request, HttpServletResponse response, Model model) {
		User us = UserUtils.getUser();
		returnsGoods.setSysUserId(UserUtils.getUser().getId());
		Page<ReturnsGoods> page = ordersExchangeHistoryService.findPage(new Page<ReturnsGoods>(request, response), returnsGoods); 
		List<Store> storeList=storeService.findStoreBySysUser(us);
		model.addAttribute("store", storeList);
		model.addAttribute("page", page);
		return "modules/sys/order/ordersexchangehistory/ordersexchangehistoryList";
	}

	@RequiresPermissions("sys:ordersexchangehistory:view")
	@RequestMapping(value = "form")
	@ResponseBody
	public Map<String,Object> form(ReturnsGoods returnsGoods) {
		Map<String,Object> resultMap = new HashMap<>();
		try{
			resultMap.putAll(ordersExchangeHistoryService.findDetail(returnsGoods));
		}catch(Exception ex){
			logger.info("form",ex);
		}
		return resultMap;
	}
}